package com.webSite.demo.cy.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.webSite.demo.cy.bean.HomeYeWu;
import com.webSite.demo.cy.mapper.HomeYeWuMapper;

@Controller
@EnableAutoConfiguration
public class HomeYeWuController {

	@Autowired
	HomeYeWuMapper homeYeWuMapper;
	
	@RequestMapping("/homeYeWu.html")
    String homeYeWu(Model model) {
		List<HomeYeWu> list = homeYeWuMapper.findAllInfo();
		if(!list.isEmpty()) {
			model.addAttribute("list", list);
		}
        return "admin/homeYeWu";  
    }
	
	@RequestMapping("/addHomeYeWu.html")  
	String addHomeYeWu(HomeYeWu homeYeWu) {
		homeYeWu.setState(1);
		homeYeWu.setCreated(new Date());
		homeYeWu.setUpdated(new Date());
		homeYeWuMapper.insertHomeYeWu(homeYeWu);
		return "redirect:/homeYeWu.html";
	}
	
	@RequestMapping("/updateYeWu.html")  
	String homeYeWu(int id,Model model) {
		HomeYeWu homeYeWu = homeYeWuMapper.findOne(id);
		model.addAttribute("homeYeWu", homeYeWu);
		return "admin/update/updateYeWu";  
	}
	
	@RequestMapping("/updateHomeYeWu.html")
	String updateHomeYeWu(HomeYeWu homeYeWu) {
		homeYeWu.setUpdated(new Date());
		homeYeWuMapper.updateHomeYeWu(homeYeWu);
		return "redirect:/homeYeWu.html";
	}
	
	@RequestMapping("/deleteYeWu.html")
	String updateState(int id) {
		homeYeWuMapper.updateState(id);
		return "redirect:/homeYeWu.html";
	}
	
}
